First things first, load in all the packages you’ll need throughout this process.
knitr::opts_chunk$set(echo = TRUE)
packages_needed <- c("ggplot2", # graphics
"arm", # display() etc.
"ggfortify")
pk_to_install <- packages_needed [!( packages_needed %in% rownames(installed.packages()) )]
if(length(pk_to_install)>0 ){
install.packages(pk_to_install,repos="http://cran.r-project.org")
}
library(ggplot2)
library(arm)
## Loading required package: MASS
## Loading required package: Matrix
## Loading required package: lme4
##
## arm (Version 1.11-2, built: 2020-7-27)
## Working directory is D:/Documents/Accademics/APSU/AdvancedData_Class/2021_09-14_AdvancedData_GLM_Assignment
library(ggfortify)
Pull in data for both analyses. I am using two of my own datasets, one which contains standardized measurments for Heloderma across their range, and another with records from Vernal Pool monitering across the northeastern part of the US.
Heloderma_Records <- read.csv("data/Heloderma_Records.csv")
Vernal_Pool_Database <- read.csv("data/Mass_Pool_Table.csv")
Start by subsetting all our information down to something we can work with. Gila monsters are notoriously hard to sex based exclusively on external characteristics, although there have been some trends observed. There have been some researchers who have reported that Male gilas tend to have broader heads than females. While this is always discribed as an imperfect means of determining sex, we can test if there is any truth to this pattern.
We subset out only monsters who have been positively sexed as “Male” or “Female” in our database, and then additionally only those monsters who have had “Head Width” measured. Then, we make a new collumn in our data “Bi_Sex” which turns our “Male” and “Female” values into 1 and 0 values so that we can apply a binary distribution to it. I also removed all juviniles and sub adults based off size thresholds set by Beck (2005) as a means of simplifying the dataset (this method is said to work much better on Adults)
Gila_Data <- Heloderma_Records[Heloderma_Records$Species == "suspectum",]
Gila_Data <- Gila_Data[is.na(Gila_Data$HW) == FALSE,]
Gila_Data <- subset(Gila_Data, Sex == "M" | Sex == "F")
Gila_Data <- Gila_Data[Gila_Data$HW != 0,]
Gila_Data <- Gila_Data[Gila_Data$SVL > 220,]
for(i in 1:dim(Gila_Data)[1]){
Gila_Data$Bi_Sex[i] <- ifelse(Gila_Data$Sex[i] == "F", 0, 1)}
head(Gila_Data)
## Source picture Catalog. Lizard_ID Species Sex Status Collection_Date
## 156 ASU ASU194.JPG 194 ASU194 suspectum M 12/28/1953
## 157 ASU ASU195.JPG 195 ASU195 suspectum F 6/3/1954
## 158 ASU ASU196.JPG 196 ASU196 suspectum F 4/29/1953
## 160 ASU ASU706.JPG 706 ASU706 suspectum F 4/17/1956
## 161 ASU ASU908.JPG 908 ASU908 suspectum M 4/5/1955
## 162 ASU ASU910.JPG 910 ASU910 suspectum F 8/26/1955
## collector Locality Collection_Notes
## 156 H.H. ROWLEYS ROOSEVELT LAKE IN CHURN
## 157 R. LATTIMORE SE OF APACHE IN CHURN
## 158 R. PRESTON BETWEEN FLORENCE AND QUEEN CREEK IN CHURN
## 160 CAMELBACK MT., SCOTTSDALE IN CHURN
## 161 BUCKEYE IN CHURN
## 162 CASA GRANDE IN CHURN
## Dissection_Notes Country
## 156 USA
## 157 rt ovid = 4 bb sized follicles USA
## 158 USA
## 160 lt ovid = 11.4, 10.1, 3peas; rt ovid = 6.3, 9.0, 11.8, and 2 peas USA
## 161 hemipenes everted USA
## 162 3 full term eggs (pics), 36.8, 34.9, 33.2 USA
## Latitude Longitude State elevation County spatial_accuracy Study
## 156 33.66378 -111.1219 Arizona 673 Gila 20
## 157 NA NA Arizona NA Maricopa NA
## 158 33.15537 -111.5181 Arizona 461 Maricopa 20
## 160 33.51444 -111.9611 Arizona 767 Maricopa 5
## 161 33.59174 -112.6895 Arizona 435 Maricopa 10
## 162 32.87905 -111.7565 Arizona 424 Pinal 5
## georef_verif SVL insert_elbow Tail elbow_wrist Tail.Diam wrist_3rd HL
## 156 Yes 314 20.9 0 22.9 29.3 29.6 54.5
## 157 ref not possible 285 20.6 130 23.9 23.0 29.6 46.4
## 158 Yes 314 17.9 145 21.8 22.1 29.9 52.2
## 160 Yes 279 18.1 129 23.2 24.1 29.7 46.3
## 161 Yes 283 19.4 158 25.8 29.3 29.5 49.6
## 162 Yes 311 19.8 135 29.6 29.0 32.4 50.6
## trunk HW Tail.Circum HL_ear_rostral Mass_grams X Bi_Sex
## 156 178 46.7 NA 61.9 NA 1
## 157 160 44.3 NA 54.0 NA 0
## 158 188 41.8 NA 56.3 NA 0
## 160 175 40.0 NA 51.0 NA 0
## 161 163 45.7 NA 53.0 NA 1
## 162 187 47.2 NA 56.9 NA 0